<?php

/**
 * Created on 24 mai 2011
 *  * @author Samy Deghou(deghou@polytech.unice.fr ; deghou@embl.de)
 * 		   Stephan Beisken (beisken@ebi.ac.uk)
 * 		   Luis Felipe De Figueiredo (ldpf@ebi.ac.uk)
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class SignalAtom implements iCRUD {
    /*
     * Attributes
     */

    private $_msSignalID;
    private $_moleculeID;

    /*
     * Constructor
     */

    public function SignalMolecule($msSignalID = -1, $moleculeID = -1) {

        $this->_msSignalID = $msSignalID;
        $this->_moleculeID = $moleculeID;
    }

    /*
     * Accessors
     */

    public function getMsSignalID() {
        return $this->_msSignalID;
    }

    public function getMoleculeID() {
        return $this->_moleculeID;
    }

    /*
     * Modifiers
     */

    public function setMsSignalID($param) {
        $this->_msSignalID = $param;
    }

    public function setMoleculeID($param) {
        $this->_moleculeID = $param;
    }

    /*
     * CRUD
     */

    /**
     * Put an object in the database
     */
    public function create() {
        Database::connect();
        if ($this->_moleculeID != -1 && $this->_msSignalID)
            die("Unable to create, still existing !");
        else {
            $query = "INSERT INTO `SIGNAL_MOLECULE` values ('" .
                    $this->_msSignalID . "','" .
                    $this->_moleculeID . "')";
            mysql_query($query) or die(mysql_error());
            $this->_idSujet = mysql_insert_id();
        }
        Database::disconnect();
    }

    /**
     * Read an object from the database
     */
    public static function read($key) {
        Database::connect();
        $query = "SELECT * FROM SIGNAL_MOLECULE WHERE ms_signal_id = '" .
                $key[0] . "' AND molecule_id '" . $key[1] . "'";
        $ans = mysql_fetch_assoc(mysql_query($query));
        extract($ans);
        Database::disconnect();
        return new SignalMolecule($ms_signal_id, $molecule_id);
        Database::disconnect();
    }

    /**
     * Update an object from the database
     */
    public function update() {
        Database::connect();

        Database::disconnect();
    }

    /**
     * Delete an object from the database
     */
    public function delete() {
        Database::connect();
        $query = "DELETE FROM `SIGNAL_MOLECULE` WHERE ms_signal_id='" .
                $this->_msSignalID . "' AND molecule_id = '" .
                $this->_moleculeID . ".";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

}
?>
